#pragma once
#include <vector>

#include "Utility/Algebra/Graph.h"
#include "Utility/Algebra/Matrix.h"
#include "Utility/Configuration/SGParameter.h"

#include "DataStructure/Common/Id.h"
#include "DataStructure/Common/SGNamespace.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/Database/DatabaseFactory.h"

#include "SGFem/Pre/Common/PreExport.h"

SG_NAMESPACE_OPEN
namespace FEMSolver
{
    /** @brief 区域分解
     *
     * 调用metis,实现网格分区
     */

    class Pre_DECLSPEC GeneratePartitioning
    {
      public:
        GeneratePartitioning ();
        // @brief metis图分解主程序
        static void SGPartitioner (SG::DBManager::DBServiceFactorySP  dbServiceFactory,
                                   SG::DataStructure::Common::IdArray NodeIds,
                                   SG::DataStructure::Common::IdArray ElementIds,
                                   SG::Algebra::Matrix                ElementNodeIds,
                                   const SG::Utility::SGParameter&    SGParameters,
                                   _OUT SG::DataStructure::Common::IdArray& SGPartitionElement);

        /// 图生成找到相邻的单元
        static Algebra::Graph GenerateElementGraph (const SG::DBManager::DBServiceFactorySP     dbServiceFactory,
                                                    std::vector<SG::DataStructure::Common::Id>& nodeIds,
                                                    const SG::DataStructure::Common::IdArray    ElementIds,
                                                    SG::Algebra::Matrix                         ElementNodeIds);

        // @brief 调用metis实现图分解
        static void GeneratePartition (const SG::DataStructure::Common::IdArray ElementIds,
                                       SG::Algebra::Graph                       g,
                                       const SG::Utility::SGParameter&          SGParameters,
                                       _OUT SG::DataStructure::Common::IdArray& SGPartitionElement);

        static void GenerateGlobalIndex (const SG::DBManager::DBServiceFactorySP dbServiceFactory,
                                         SG::DataStructure::Common::IdArray&     SGPartitionElement,
                                         const SG::Utility::SGParameter&         SGParameters,
                                         SG::DataStructure::Common::IdArray      NodeIds,
                                         SG::DataStructure::Common::IdArray      ElementIds,
                                         SG::DataStructure::Common::IdArray _OUT PartitionIndex);
        // static void AddCQuadData (DBServiceFactory* dbf, Id const id);

      private:
    };

};  // namespace FEMSolver
SG_NAMESPACE_CLOSE